package com.kanshu.ksgb.fastread.doudou.module.personal.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.module.personal.activity.ChargeFragment;
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.PayConfig;

import java.util.List;

import static com.kanshu.ksgb.fastread.doudou.module.personal.activity.ChargeFragment.TYPE_REMOVE_AD;

/**
 * Created by wcy on 18/5/24.
 */

public class RechargeAdapter extends BaseQuickAdapter<PayConfig> {

    int type = ChargeFragment.TYPE_CHARGE;
    public RechargeAdapter(Context context, List<PayConfig> data, int type) {
        super(context, data);
        this.type = type;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.layout_pay_config_item;
    }

    @Override
    protected void convert(BaseViewHolder holder, PayConfig item, int position) {

        String rmbTxt;
        String coinTxt;
        if(type == TYPE_REMOVE_AD){
            rmbTxt  = (Integer.valueOf(item.total_fee)/100) +" 元";
            coinTxt = getNoAdText(item);
        }else{
            rmbTxt =item.pay_fee + "元";
            coinTxt = getCoinText(item);
        }
        holder.setText(R.id.coin_info,coinTxt);
        holder.setText(R.id.rmb,rmbTxt);
    }

    private  String getNoAdText(PayConfig payConfig) {
        String res;
        if(TextUtils.equals("-1",payConfig.pay_day)){
            res = "永久免广告";
        }else{
            res = "免广告" + payConfig.pay_day +"天";
        }
        return res;
    }
    private String getCoinText( PayConfig payConfig) {
        StringBuilder builder = new StringBuilder();
        builder.append(Integer.parseInt(payConfig.pay_fee) * Integer.parseInt( payConfig.pay_rate));
        builder.append("+");
        builder.append(Integer.parseInt(payConfig.give_fee) * Integer.parseInt(payConfig.pay_rate));
        builder.append("金币");
        return builder.toString();

    }
}
